package com.example.easybuy.controller;

import com.example.easybuy.pojo.Order;
import com.example.easybuy.pojo.User;
import com.example.easybuy.service.OrderService;
import com.example.easybuy.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class OrderController {

    private Logger logger=Logger.getLogger(getClass());

    @Autowired
    private OrderService orderService;

    @Autowired
    private UserService userService;

    /*
    查询当前用户订单信息
     */
    @RequestMapping("getOrderList")
    @ResponseBody
    @CrossOrigin
    public List<Order> getOrderList(){
        logger.debug("OrderController-getOrderList（）...start...");
        //拿出存放在redies的user对象
        User user =userService.getUser();
        int userId=user.getId();
        logger.debug("OrderController-getOrderList（）-userId："+userId);
        List<Order> orderList=orderService.getOrderList(userId);
        logger.debug("OrderController-getOrderList（）-orderList："+orderList);
            return orderList;
    }

    /*
    查询全部订单信息
     */
    @RequestMapping("getOrderListAll")
    @ResponseBody
    @CrossOrigin
    public List<Order> getOrderListAll(){
        logger.debug("OrderController-getOrderListAll（）...start...");
        int userId=0;
        List<Order> orderList=orderService.getOrderList(userId);
        logger.debug("OrderController-getOrderListAll（）-orderList："+orderList);
        return orderList;
    }


    /*
    删除订单信息
     */
    @RequestMapping("deletOrderdatail")
    @ResponseBody
    @CrossOrigin
    public String deletOrderdatail(String id){
        logger.debug("OrderController-deletOrderdatail（）-id："+id);
        String success=orderService.deletOrderdatail(id);
        logger.debug("OrderController-deletOrderdatail（）-success："+success);
        return success;
    }

}
